package com.linkgie.galaxyframework.metadata.structure;

import javax.validation.constraints.NotBlank;

import com.linkgie.galaxyframework.metadata.BaseField;
import com.linkgie.galaxyframework.metadata.DataEntity;
import com.linkgie.galaxyframework.metadata.DataField;
import com.linkgie.galaxyframework.metadata.DataInterface;
import com.linkgie.galaxyframework.metadata.DataKey;
import com.linkgie.galaxyframework.metadata.DataLabel;
import com.linkgie.galaxyframework.metadata.DataType;
import com.linkgie.galaxyframework.metadata.DefaultBoolean;
import com.linkgie.galaxyframework.metadata.DefaultInteger;
import com.linkgie.galaxyframework.metadata.IteratorOperation;

/**
 * 字段元数据；
 * 
 * @author huanghaiquan
 *
 */
@DataInterface
@DataEntity
public class FieldMetadata implements BaseField {

	@NotBlank
	@DataKey
	@DataField(name = "字段键", order = 0)
	private String key;

	@DataLabel
	@NotBlank
	@DataField(name = "字段名", order = 1)
	private String name;

	@DefaultInteger(0)
	@NotBlank
	@DataField(name = "顺序", order = 20)
	private int order = 0;

	@DefaultBoolean(false)
	@NotBlank
	@DataType(contentType = "enum;strict=true;true='是';false='否'")
	@DataField(name = "只读", order = 21)
	private boolean readonly = false;

	/**
	 * {@link #readonly} 比 {@link #writeonly} 有更高优先级，<br>
	 * 只有 readonly 为 fale 时，writeonly 的设置才有效；
	 */
	@NotBlank
	@DefaultBoolean(false)
	@DataType(contentType = "enum;strict=true;true='是';false='否'")
	@DataField(name = "只写", order = 22)
	private boolean writeonly = false;

	@NotBlank
	@DefaultBoolean(true)
	@DataType(contentType = "enum;strict=true;true='是';false='否'")
	@DataField(name = "可修改", order = 23)
	private boolean modifiable = true;

	@NotBlank
	@DefaultBoolean(true)
	@DataType(contentType = "enum;strict=true;true='是';false='否'")
	@DataField(name = "隐藏字段", order = 24)
	private boolean hide = false;

	/**
	 * 当字段为可迭代类型时，支持的对字段的数据列表的操作；
	 * 
	 * <p>
	 * 默认支持增加(Add)、修改(Update)、删除(Delete)操作；
	 * 
	 * @return
	 */
	@DataField(name = "列表操作", order = 25)
	private IteratorOperation[] iterates = new IteratorOperation[] { IteratorOperation.ADD, IteratorOperation.UPDATE,
			IteratorOperation.DELETE };

	@DataField(name = "提示信息", order = 30)
	private String hint;

	@Override
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	/**
	 * 字段名称；
	 * <p>
	 * 
	 * 注：对于接口而言，接口字段的名称只有参考意义，实际中要基于 key 匹配相应的模型的字段名称；
	 */
	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean isReadonly() {
		return readonly;
	}

	public void setReadonly(boolean readonly) {
		this.readonly = readonly;
	}

	@Override
	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public boolean isWriteonly() {
		return writeonly;
	}

	public void setWriteonly(boolean writeonly) {
		this.writeonly = writeonly;
	}

	public boolean isModifiable() {
		return modifiable;
	}

	public void setModifiable(boolean modifiable) {
		this.modifiable = modifiable;
	}

	public IteratorOperation[] getIterates() {
		return iterates;
	}

	public void setIterates(IteratorOperation[] iterates) {
		this.iterates = iterates;
	}

	/**
	 * @return the hide
	 */
	public boolean isHide() {
		return hide;
	}

	/**
	 * @param hide the hide to set
	 */
	public void setHide(boolean hide) {
		this.hide = hide;
	}

	/**
	 * @return the hint
	 */
	public String getHint() {
		return hint;
	}

	/**
	 * @param hint the hint to set
	 */
	public void setHint(String hint) {
		this.hint = hint;
	}

	// public String getDataKey() {
	// return dataKey;
	// }
	//
	// public void setDataKey(String dataKey) {
	// this.dataKey = dataKey;
	// }

}
